package org.ace.biz.user.impl;

import javax.annotation.Resource;

import org.ace.basicdata.IBasicDataCentral;
import org.ace.basicdata.model.ItemBasicData;
import org.ace.biz.user.IPlayerBiz;
import org.ace.biz.user.IPlayerItemBiz;
import org.ace.biz.user.IShopBiz;
import org.springframework.stereotype.Service;
@Service("shopBiz")
public class ShopBiz implements IShopBiz {
	
    @Resource(name="itemBasicDataCenteral")
	private IBasicDataCentral<ItemBasicData> itemBasicDataCenteral;
    
    @Resource(name="playerBiz")
    private IPlayerBiz playerBiz;
    
    @Resource(name="playerItemBiz")
    private IPlayerItemBiz playerItemBiz;
    
	@Override
	public int buy(Integer userId, Integer gdCode, Integer count) {
		//从配置文件 获取 有没有这个道具
		if(!itemBasicDataCenteral.has(gdCode)) return -1;
		//获取道具价格
		ItemBasicData data =itemBasicDataCenteral.get(gdCode);
		int price=data.getPrice()*count;
		//扣除单价*数量金币 是否成功
		if(!playerBiz.spendMoney(userId, price)) return -1;
		//给予道具 并返回消耗的金额
		playerItemBiz.add(userId,gdCode,count) ;
		
		
		return price;
	}

}
